package com.tinshow.config.freemarker;

import freemarker.template.TemplateException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;

import javax.annotation.PostConstruct;
import java.util.Properties;

@Configuration
public class FreeMarkerConfig {
	
//	    @PostConstruct
//	    public void  setSharedVariable(){
//	        configuration.setDateFormat("yyyy/MM/dd");
//	        configuration.setDateTimeFormat("yyyy-MM-dd HH:mm:ss");
//	        try {
//	            configuration.setSetting("template_update_delay", "1");
//	            configuration.setSetting("default_encoding", "UTF-8");
//	        } catch (TemplateException e) {
//	            e.printStackTrace();
//	        }
//	        springResolver.setPrefix("/XXX/");
//	        springResolver.setSuffix(".jsp");
//	        springResolver.setOrder(1);
//	        resolver.setSuffix(".html");
//	        resolver.setCache(false);
//	        resolver.setRequestContextAttribute("request");
//	        resolver.setOrder(0);
//	    }

	    @Bean(name = "viewResolver")
	    public FreeMarkerViewResolver freeMarkerViewResolver(){
	    	FreeMarkerViewResolver fmvr = new FreeMarkerViewResolver();
	    	fmvr.setRequestContextAttribute("request");
            fmvr.setPrefix("");
            fmvr.setSuffix(".ftl");
            fmvr.setContentType("text/html; charset=UTF-8");
	    	return fmvr;
	    }


}
